package com.yihuan.global;


import com.yihuan.entity.SellerEntity;
import com.yihuan.entity.UserEntity;

import javax.servlet.http.HttpSession;

public class vms_variable_global {
    //保持两个小时
    public String variableName(HttpSession session, SellerEntity model) {
        //存储登录账号昵称
        session.setAttribute("SellerNickname", model.getSellerNickname());
        //存储登录账号
        session.setAttribute("SellerLoginName", model.getSellerLoginName());
        //存储登录账号的姓名
        session.setAttribute("SellerID", model.getSellerID());
        //设置登录持续时间保持两个小时
        session.setMaxInactiveInterval(2 * 60 * 60);
        return null;
    }
    
    //超级管理员
    public String variableNameTime(HttpSession session, UserEntity model) {
        //存储登录账号昵称
        session.setAttribute("UserNickname", model.getUserNickname());
        //存储登录账号
        session.setAttribute("UserLoginName", model.getUserLoginName());
        System.out.println(model.getUserID());
        //存储登录账号的姓名
        session.setAttribute("UserID", model.getUserID());
        //设置登录持续时间保持七天
        session.setMaxInactiveInterval(7 * 24 * 60 * 60);
        return null;
    }
    
    //回收员
    public String variableNameTime_3(HttpSession session, UserEntity model) {
        //存储登录账号昵称
        session.setAttribute("UserNickname_3", model.getUserNickname());
        //存储登录账号
        session.setAttribute("UserLoginName_3", model.getUserLoginName());
        System.out.println(model.getUserID());
        //存储登录账号的姓名
        session.setAttribute("UserID_3", model.getUserID());
        //设置登录持续时间保持七天
        session.setMaxInactiveInterval(7 * 24 * 60 * 60);
        return null;
    }
    
    //普通用户
    public String variableNameTime_4(HttpSession session, UserEntity model) {
        //存储登录账号昵称
        session.setAttribute("UserNickname_4", model.getUserNickname());
        //存储登录账号
        session.setAttribute("UserLoginName_4", model.getUserLoginName());
        System.out.println(model.getUserID());
        //存储登录账号的姓名
        session.setAttribute("UserID_4", model.getUserID());
        //设置登录持续时间保持七天
        session.setMaxInactiveInterval(7 * 24 * 60 * 60);
        return null;
    }
    /**
     * 判断登录账号是否存在
     * 如果500表示没有名字
     * 如果200表示有名字
     *
     * @param request
     * @return
     */
//    public int variableNameSession(HttpServletRequest request) {
//        HttpSession session = request.getSession();
//        String UserLoginName = (String) session.getAttribute("UserLoginName");
//        if (UserLoginName == null) {
//            return 500;
//        }
//        return 200;
//    }
    
  /*public String sessionName(HttpServletRequest request) {
        HttpSession session = request.getSession();
        String UserLoginName = (String) session.getAttribute("UserLoginName");
        return UserLoginName;
    }
    
    
    @Override
    public String variableYeZhuName(HttpSession session, Forest_yezhumessage model) {
        //存储用户名
        session.setAttribute("username", model.getYeZhuName());
        session.setAttribute("userId", model.getYeZhuID());
        System.out.println(model.getYeZhuID());
        //2个小时
        session.setMaxInactiveInterval(7 * 24 * 60 * 60);
        return null;
    }
    
    public int sessionID(HttpServletRequest request) {
        HttpSession session = request.getSession();
        Object userId = session.getAttribute("userId");
        System.out.println(userId);
        int u = (int) userId;
        return u;
    }
    
    */
    
    /**
     * 如果500表示没有名字
     * 如果200表示有名字
     *
     * @param
     * @return
     *//*
    @Override
    public int variableYeZhuNameSession(HttpServletRequest request) {
        HttpSession session = request.getSession();
        String name = (String) session.getAttribute("username");
        if (name == null) {
            return 500;
        }
        return 200;
    }
    
    public String variableYeZhuName(HttpServletRequest request) {
        HttpSession session = request.getSession();
        String name = (String) session.getAttribute("username");
        return name;
    }*/
    //保持两个小时
//    public String variableUserCommonName(HttpSession session, UserCommonEntity model) {
//        //存储登录账号昵称
//        session.setAttribute("userCommonLoginName", model.getUserCommonLoginName());
//        //存储登录账号
//        session.setAttribute("userCommonNickname", model.getUserCommonNickname());
//        //存储登录账号的姓名
//        session.setAttribute("userCommonID", model.getUserCommonID());
//        //设置登录持续时间保持两个小时
//        session.setMaxInactiveInterval(2 * 60 * 60);
//        return null;
//    }
}
